<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="prev" href="node521.html" />
<link rel="parent" href="module-resource.html" />
<link rel="next" href="module-nis.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>16.13.2 Resource Usage</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="16.13.1 resource Limits"
  href="node521.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="16.13 resource  "
  href="module-resource.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="16.14 nis  "
  href="module-nis.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="node521.html">16.13.1 Resource Limits</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-resource.html">16.13 resource  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-nis.html">16.14 nis  </a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION00181320000000000000000">
16.13.2 Resource Usage</a>
</h2>

<p>
These functions are used to retrieve resource usage information:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3606' xml:id='l2h-3606' class="function">getrusage</tt></b>(</nobr></td>
  <td><var>who</var>)</td></tr></table></dt>
<dd>
  This function returns an object that describes the resources
  consumed by either the current process or its children, as specified
  by the <var>who</var> parameter.  The <var>who</var> parameter should be
  specified using one of the <tt class="constant">RUSAGE_*</tt> constants described
  below.

<p>
The fields of the return value each describe how a particular system
  resource has been used, e.g. amount of time spent running is user mode
  or number of times the process was swapped out of main memory. Some
  values are dependent on the clock tick internal, e.g. the amount of
  memory the process is using.

<p>
For backward compatibility, the return value is also accessible as
  a tuple of 16 elements.

<p>
The fields <tt class="member">ru_utime</tt> and <tt class="member">ru_stime</tt> of the return value
  are floating point values representing the amount of time spent
  executing in user mode and the amount of time spent executing in system
  mode, respectively. The remaining values are integers. Consult the
  <span class="manpage"><i>getrusage</i>(2)</span> man page for detailed information about these
  values. A brief summary is presented here:

<p>
<div class="center"><table class="realtable">
  <thead>
    <tr>
      <th class="right" >Index</th>
      <th class="left"  >Field</th>
      <th class="left"  >Resource</th>
      </tr>
    </thead>
  <tbody>
    <tr><td class="right"  valign="baseline"><code>0</code></td>
        <td class="left"  ><tt class="member">ru_utime</tt></td>
        <td class="left"  >time in user mode (float)</td></tr>
    <tr><td class="right"  valign="baseline"><code>1</code></td>
        <td class="left"  ><tt class="member">ru_stime</tt></td>
        <td class="left"  >time in system mode (float)</td></tr>
    <tr><td class="right"  valign="baseline"><code>2</code></td>
        <td class="left"  ><tt class="member">ru_maxrss</tt></td>
        <td class="left"  >maximum resident set size</td></tr>
    <tr><td class="right"  valign="baseline"><code>3</code></td>
        <td class="left"  ><tt class="member">ru_ixrss</tt></td>
        <td class="left"  >shared memory size</td></tr>
    <tr><td class="right"  valign="baseline"><code>4</code></td>
        <td class="left"  ><tt class="member">ru_idrss</tt></td>
        <td class="left"  >unshared memory size</td></tr>
    <tr><td class="right"  valign="baseline"><code>5</code></td>
        <td class="left"  ><tt class="member">ru_isrss</tt></td>
        <td class="left"  >unshared stack size</td></tr>
    <tr><td class="right"  valign="baseline"><code>6</code></td>
        <td class="left"  ><tt class="member">ru_minflt</tt></td>
        <td class="left"  >page faults not requiring I/O</td></tr>
    <tr><td class="right"  valign="baseline"><code>7</code></td>
        <td class="left"  ><tt class="member">ru_majflt</tt></td>
        <td class="left"  >page faults requiring I/O</td></tr>
    <tr><td class="right"  valign="baseline"><code>8</code></td>
        <td class="left"  ><tt class="member">ru_nswap</tt></td>
        <td class="left"  >number of swap outs</td></tr>
    <tr><td class="right"  valign="baseline"><code>9</code></td>
        <td class="left"  ><tt class="member">ru_inblock</tt></td>
        <td class="left"  >block input operations</td></tr>
    <tr><td class="right"  valign="baseline"><code>10</code></td>
        <td class="left"  ><tt class="member">ru_oublock</tt></td>
        <td class="left"  >block output operations</td></tr>
    <tr><td class="right"  valign="baseline"><code>11</code></td>
        <td class="left"  ><tt class="member">ru_msgsnd</tt></td>
        <td class="left"  >messages sent</td></tr>
    <tr><td class="right"  valign="baseline"><code>12</code></td>
        <td class="left"  ><tt class="member">ru_msgrcv</tt></td>
        <td class="left"  >messages received</td></tr>
    <tr><td class="right"  valign="baseline"><code>13</code></td>
        <td class="left"  ><tt class="member">ru_nsignals</tt></td>
        <td class="left"  >signals received</td></tr>
    <tr><td class="right"  valign="baseline"><code>14</code></td>
        <td class="left"  ><tt class="member">ru_nvcsw</tt></td>
        <td class="left"  >voluntary context switches</td></tr>
    <tr><td class="right"  valign="baseline"><code>15</code></td>
        <td class="left"  ><tt class="member">ru_nivcsw</tt></td>
        <td class="left"  >involuntary context switches</td></tr></tbody>
</table></div>

<p>
This function will raise a <tt class="exception">ValueError</tt> if an invalid
  <var>who</var> parameter is specified. It may also raise
  <tt class="exception">error</tt> exception in unusual circumstances.

<p>

<span class="versionnote">Changed in version 2.3:
Added access to values as attributes of the
  returned object.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3607' xml:id='l2h-3607' class="function">getpagesize</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Returns the number of bytes in a system page. (This need not be the
  same as the hardware page size.) This function is useful for
  determining the number of bytes of memory a process is using. The
  third element of the tuple returned by <tt class="function">getrusage()</tt> describes
  memory usage in pages; multiplying by page size produces number of
  bytes. 
</dl>

<p>
The following <tt class="constant">RUSAGE_*</tt> symbols are passed to the
<tt class="function">getrusage()</tt> function to specify which processes information
should be provided for.

<p>
<dl><dt><b><tt id='l2h-3608' xml:id='l2h-3608'>RUSAGE_SELF</tt></b></dt>
<dd>
  <tt class="constant">RUSAGE_SELF</tt> should be used to
  request information pertaining only to the process itself.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-3609' xml:id='l2h-3609'>RUSAGE_CHILDREN</tt></b></dt>
<dd>
  Pass to <tt class="function">getrusage()</tt> to request resource information for
  child processes of the calling process.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-3610' xml:id='l2h-3610'>RUSAGE_BOTH</tt></b></dt>
<dd>
  Pass to <tt class="function">getrusage()</tt> to request resources consumed by both
  the current process and child processes.  May not be available on all
  systems.
</dd></dl>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="16.13.1 resource Limits"
  href="node521.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="16.13 resource  "
  href="module-resource.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="16.14 nis  "
  href="module-nis.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="node521.html">16.13.1 Resource Limits</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-resource.html">16.13 resource  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-nis.html">16.14 nis  </a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
